package it.milanoeasy.gae;

import java.io.Serializable;
import javax.servlet.http.HttpServletRequest;

public class User implements Serializable {
	com.google.appengine.api.users.User gUser=null;
	String nickname="";
	String userId="_123654789_";
	String email="unknown@gmail.com";
	String authDomain="appspot.com";
	String federatedIdentity="federatedId";
	boolean loggedOnGoogle=false;
	 
	public User(){
		setLoggedOnGoogle(gUser!=null);
	}
	
	public User(com.google.appengine.api.users.User gUser){
		this.gUser=gUser;
		setLoggedOnGoogle(gUser!=null);
	}
	
	public static String getRequestURI(HttpServletRequest request){
		String ret=request.getRequestURI();
		int val=ret.lastIndexOf(".jsp");
		if (val!=-1){
			ret=ret.substring(0,val);
		} 
		return ret;
	}
	
	public boolean isLoggedOnGoogle() {
		return loggedOnGoogle;
	}
	
	public void setLoggedOnGoogle(boolean loggedOnGoogle) {
		this.loggedOnGoogle = loggedOnGoogle;
	}
	public String getNickname() {
		if (gUser!=null){
			return gUser.getNickname();
		} else {
			return nickname;
		}
	}
	public void setNickname(String nickname) {		
		this.nickname = nickname;
		
	}
	public String getUserId() {
		if (gUser!=null){
			return gUser.getUserId();
		} else {
			return userId;
		}
	}
	public void setUserId(String userId) {
		this.userId = userId;
	}
	public String getEmail() {
		if (gUser!=null){
			return gUser.getEmail();
		} else {
			return email;
		}
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getAuthDomain() {
		if (gUser!=null){
			return gUser.getAuthDomain();
		} else {
		return authDomain;
		}
	}
	public void setAuthDomain(String authDomain) {
		this.authDomain = authDomain;
	}
	public String getFederatedIdentity() {
		if (gUser!=null){
			return gUser.getFederatedIdentity();
		} else {
			return federatedIdentity;
		}
	}
	public void setFederatedIdentity(String federatedIdentity) {
		this.federatedIdentity = federatedIdentity;
	}
	
	
	
}
